package work.content.judge_generate;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import lombok.Data;

public interface Setting {
    String dir = "C:\\work-records\\l陆叶\\s-content\\评委名单\\";
    String dataPath = dir + "data2.xlsx";

    String outPath = dir + "result.sql";

    String sql = """
            INSERT INTO busi_user (user_name,  email,  user_role) VALUES
            %s;
            """;
    String sqlItem = "( '%s', '%s',  'judges'),\n";

    /**
     * 邮箱对象
     */
    @Data
    class MyExcelObject {
        @ExcelProperty("Full Name")
        private String name;

        @ExcelProperty("Professional Email")
        private String email;

        public String getSqlItem() {
            return String.format(sqlItem, name, email);
        }
    }

    class MyExcelReadListener implements ReadListener<MyExcelObject> {

        private final ExcelInvoke excelInvoke;
        private final ExcelDoAfterAllAnalysed afterAllAnalysed;

        public MyExcelReadListener(ExcelInvoke excelInvoke, ExcelDoAfterAllAnalysed afterAllAnalysed) {
            this.excelInvoke = excelInvoke;
            this.afterAllAnalysed = afterAllAnalysed;
        }

        @Override
        public void invoke(MyExcelObject myExcelObject, AnalysisContext analysisContext) {
            excelInvoke.invoke(myExcelObject, analysisContext);
        }

        @Override
        public void doAfterAllAnalysed(AnalysisContext analysisContext) {
            afterAllAnalysed.doAfterAllAnalysed(analysisContext);
        }
    }

    interface ExcelInvoke {
        void invoke(MyExcelObject myExcelObject, AnalysisContext analysisContext);
    }

    interface ExcelDoAfterAllAnalysed {
        void doAfterAllAnalysed(AnalysisContext analysisContext);
    }
}

